#!/usr/bin/env python
# -*- coding: utf-8 -*-

from string import Template

#user
#s = {"weixin":"string","alipayName":"string","alipayNo":"string","bankName":"string","bankNo":"string","bankAccount":"string","intermediaryId":"int","intermediaryName":"string"};
#project
#s = {"id":"int","title":"string","brokerStr1":"string","personStr1":"string","discountStr":"string","costPrice":"string","introduction":"string","hotTip":"string","buildingId":"int","buildingName":"string","details":"string","comment":"string","mobileDetails":"string"};
#recommend
s = {"id":"int","fullName":"string","unitPrice":"string","phoneNumber":"string","intentionalArea":"string","sumTotla":"string","buildingId":"int","buildingName":"string","type":"string","isSchoolRoom":"int","buyingTime":"string","intentionalRegion":"string","remarks":"string","userId":"int","userName":"string","userTel":"string","status":"int","instructions":"string"};
#building
#s = {"id":"int","userName":"string","userPwd":"string","name":"string","contactName":"string","contactTel":"string","address":"string","position":"string","other":"string"};

t = {"int":"OleDbType.Integer,4","string":"OleDbType.VarChar,255","textarea":"OleDbType.VarChar"}

def getsType(st):
    return t.get(st);


#dal
def getparse1():
     s1 = "";
     code = Template(''',${paramName}''');
     for i in s:
         aa = code.substitute({"paramName":i});
         s1 = aa + s1;
     print s1;


def getparse2():
     s1 = "";
     code = Template('''new OleDbParameter("@${paramName}", ${paramType}),\n''');

     for i in s:
         name = i;
         paramType = getsType(s.get(i));
         aa = code.substitute({"paramName":name,"paramType":paramType});
         s1 = aa + s1;
     print s1;

def getparse3():
     s1 = "";
     code = Template('''strSql.Append("${paramName}=@${paramName},");\n''');
     for i in s:
         paramName = i;
         aa = code.substitute({"paramName":paramName});
         s1 = aa + s1;
     print s1;

def getparse4():
     s1 = "";
     code = Template('''parameters[${ii}].Value = model.${paramName};\n''');
     n = 0;
     for i in s:
         ii = n;
         n = n +1;
         paramName = i;
         aa = code.substitute({"ii":ii,"paramName":paramName});
         s1 = aa + s1;
     print s1;


def getparse5():
     s1 = "";
     code = Template('''if (ds.Tables[0].Rows[0]["${paramName}"] != null && ds.Tables[0].Rows[0]["${paramName}"].ToString() != "")
                {
                    model.${paramName} = ${paramParse};
                }\n''');
     for i in s:
         paramName = i;
         if(s.get(i)=="int"):
             paramParse = "int.Parse(ds.Tables[0].Rows[0][\""+ i +"\"].ToString())";
         else:
             paramParse = "ds.Tables[0].Rows[0][\"" + i + "\"].ToString()";
         aa = code.substitute({"paramName":paramName,"paramParse":paramParse});
         s1 = aa + s1;
     print s1;

#model
def getparse6():
     s1 = "";
     code = Template('''private ${paramType} _${paramName} = ${DefaultValue};
     public ${paramType} ${paramName}
        {
            set { _${paramName} = value; }
            get { return _${paramName}; }
        }\n''');
     for i in s:
         paramName = i;
         paramType = s.get(i);
         if paramType == "int":
             DefaultValue = "0";
         else:
             DefaultValue = "String.Empty";
         aa = code.substitute({"paramName":paramName,"paramType":paramType,"DefaultValue":DefaultValue});
         s1 = aa + s1;
     print s1;

def getparse7():
     s1 = "";
     code = Template(''',@${paramName}''');
     for i in s:
         aa = code.substitute({"paramName":i});
         s1 = aa + s1;
     print s1;


#getparse6();
#getparse1();
#getparse2();
# getparse3();
getparse4();
# getparse5();
# getparse7();
